<template>
  <view>
    <view class="card">
      <view class="c-top" @click="toimg(detail)">
        <view>
          <view class="type">
            <text class="typetitle"
              >{{ detail.invoiceTypeEnum.value }}发票</text
            >
            ：{{ detail.invoiceConditionEnum.value }}
          </view>
          <view class="time">申请日期:{{ detail.createTime }}</view>
        </view>
        <view class="look" v-if="detail.invoiceConditionEnum.key == 2">
          查看
          <image src="/static/img/hyj.png" mode />
        </view>
      </view>
      <view class="line"></view>
      <view class="c-bottom">
        <view class="item">发票抬头：{{ detail.invoiceTitle }}</view>
        <view class="item">发票金额：￥{{ detail.invoiceValue }}</view>
        <!-- <view class="item">发票内容：住宿服务费</view> -->
        <view class="item">联系号码：{{ detail.phoneNumber }}</view>
        <view class="item"
          >邮箱地址：{{ detail.email ? detail.email : "--" }}</view
        >
      </view>
    </view>
    <div
      class="downpdf"
      @click="topdf"
      v-if="detail.invoiceConditionEnum.key == 2"
    >
      复制PDF链接
    </div>
  </view>
</template>

<script>
export default {
  data() {
    return {
      data: "",
      detail: "",
    };
  },
  methods: {
    toimg(v) {
      if (this.detail.invoiceConditionEnum.key != 2) {
        return;
      }
      if (!this.detail.pdfUrl) {
        uni.showToast({
          title: "暂无发票",
          icon: "none",
          duration: 2000,
        });
        return;
      }
      uni.showLoading({
        title: "打开中",
      });
      uni.downloadFile({
        url: v.pdfUrl,
        success: function (res) {
          var filePath = res.tempFilePath;
          uni.openDocument({
            filePath: filePath,
            fileType: "pdf",
            success: function (res) {
              console.log("打开文档成功");
              uni.hideLoading();
            },
            fail(res) {
              console.log(res);
              uni.showToast({
                icon: "none",
                title: "打开文档失败",
                duration: 2000,
              });
              uni.hideLoading();
            },
          });
        },
      });
      // uni.navigateTo({
      //   url:
      //     "/pages/invoiceimg/invoiceimg?img=" +
      //     v.fileUrl +
      //     "&pdfUrl=" +
      //     v.pdfUrl
      // });
    },
    topdf(v) {
      if (!this.detail.pdfUrl) {
        uni.showToast({
          icon: "none",
          title: "暂无发票链接",
          duration: 2000,
        });
        return;
      }
      console.log(this.detail.pdfUrl);
      uni.setClipboardData({
        data: this.detail.pdfUrl,
        success: function () {
          uni.showToast({
            icon: "none",
            title: "复制成功,请到浏览器下载",
            duration: 3000,
          });
        },
      });
    },
    getdetail() {
      this.$http
        .get(
          "/invoiceRecord/details",
          {
            id: this.data.invoiceId,
          },
          {
            header: {
              "content-type": "application/json;charset=UTF-8",
            } /* 会覆盖全局header */,
            dataType: "json",
            responseType: "text",
          }
        )
        .then((res) => {
          let data = res.data;
          if (data.code == 0) {
            // data.data.forEach(item => {
            //   item.entryTime = this.$moment(item.entryTime).format("MM-DD");
            //   item.leaveTime = this.$moment(item.leaveTime).format("MM-DD");
            // });
            data.data.createTime = this.$moment(data.data.createTime).format(
              "YYYY-MM-DD HH:mm:ss"
            );
            this.detail = data.data;
          } else {
            uni.showToast({
              image: "/static/img/warn.png",
              title: data.msg,
              duration: 2000,
              mask: true,
            });
          }
        })
        .catch((err) => {});
    },
  },
  onLoad(options) {
    this.data = JSON.parse(options.item);
    this.getdetail();
  },
};
</script>

<style scoped>
.card {
  width: 702rpx;
  background: rgba(255, 255, 255, 1);
  border: 1px solid rgba(245, 245, 245, 1);
  box-shadow: 0px 8rpx 10rpx 0px rgba(0, 0, 0, 0.1);
  border-radius: 16rpx;
  margin: auto;
  margin-top: 40rpx;
  padding: 37rpx 0rpx 0 0;
}
.c-top {
  padding: 37rpx 24rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.type {
  font-size: 32rpx;
  font-family: PingFang SC;
  font-weight: 500;
  color: rgba(0, 0, 0, 1);
}
.typetitle {
  font-size: 32rpx;
  font-family: PingFang SC;
  font-weight: bold;
  color: rgba(0, 0, 0, 1);
}
.time {
  font-size: 28rpx;
  font-family: PingFang SC;
  font-weight: 500;
  color: rgba(121, 121, 121, 1);
  margin-top: 20rpx;
}
.look {
  font-size: 28rpx;
  font-family: PingFang SC;
  font-weight: 500;
  color: rgba(0, 0, 0, 1);
  display: flex;
  align-items: center;
}
.look image {
  height: 18rpx;
  width: 18rpx;
  margin-left: 10rpx;
}
.line {
  width: 100%;
  height: 20rpx;
  background: rgba(245, 245, 245, 1);
}
.c-bottom {
  padding: 37rpx 24rpx;
  font-size: 28rpx;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: rgba(121, 121, 121, 1);
}
.c-bottom .item {
  line-height: 58rpx;
}
.downpdf {
  font-size: 28rpx;
  font-family: PingFang SC;
  font-weight: 500;
  color: rgba(67, 130, 255, 1);
  text-align: center;
  margin-top: 20px;
}
</style>
<style >
page {
  background-color: #ffffff !important;
}
</style>